package com.school.edupoint.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Value("${rabbitmq.queue.name}")
    private String queueName;

    @Value("${rabbitmq.exchange.name}")
    private String exchangeName;

    @Value("${rabbitmq.route.key}")
    private String routeKey;

    // 声明队列（持久化）
    @Bean
    public Queue activityQueue() {
        // 参数：队列名, 持久化, 非独占, 非自动删除
        return QueueBuilder.durable(queueName).build();
    }

    @Bean
    public DirectExchange directExchange() {
        // 参数：队列名, 持久化, 非独占, 非自动删除
        return ExchangeBuilder.directExchange(exchangeName).build();
    }

    // 绑定队列到默认交换机
    @Bean
    public Binding binding(Queue activityQueue, DirectExchange directExchange) {
        return BindingBuilder.bind(activityQueue).to(directExchange).with(routeKey);

    }


}